package com.bite.user.config;

import com.bite.common.constant.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    @Bean("helloQueue")
    public Queue queue() {
        return QueueBuilder.durable("hello").build();
    }

    //用户队列
    @Bean("userQueue")
    public Queue userQueue() {
        // durable:是否持久化
        return QueueBuilder.durable(Constants.USER_QUEUE_NAME).build();
    }

    //交换机
    @Bean("userExchange")
    public FanoutExchange userExchange() {
        return ExchangeBuilder.fanoutExchange(Constants.USER_EXCHANGE_NAME).durable(true).build();
    }

    //交换机和队列的绑定
    @Bean("userBinding")
    public Binding userBinding(@Qualifier("userQueue") Queue userQueue, @Qualifier("userExchange") FanoutExchange userExchange) {
        return BindingBuilder.bind(userQueue).to(userExchange);
    }

//    @Bean("userQueue")
//    public Queue userQueue(){
//        return QueueBuilder.durable(Constants.USER_QUEUE_NAME).build();
//    }
//    @Bean("userExchange")
//    public FanoutExchange userExchange(){
//        return ExchangeBuilder.fanoutExchange(Constants.USER_EXCHANGE_NAME).durable(true).build();
//    }
//
//    @Bean("userBinding")
//    public Binding userBinding(@Qualifier("userQueue") Queue userQueue, @Qualifier("userExchange") FanoutExchange userExchange){
//        return BindingBuilder.bind(userQueue).to(userExchange);
//    }

}
